import { ApiRequest } from '@/interface/request';
import { MyRootThunkAction, RootState } from '@/interface/store';
import { user, userlog } from '@/interface/user';
import axios from '@/utils/request';
import { message } from 'antd';

/**
 * 获取用户信息
 */
export const getUserInfo = (): MyRootThunkAction => {
    return async (dispatch) => {
        const res = await axios.get<ApiRequest<user>>('/api/userInfo');
        dispatch({
            type: 'user/getUserInfo',
            payload: res.data.data,
        });
    };
};
/**
 * 获取用户日志
 */
export const getUserLog = (): MyRootThunkAction => {
    return async (dispatch) => {
        const res = await axios.get<ApiRequest<userlog>>('/api/userLog');
        dispatch({
            type: 'user/getUserLog',
            payload: res.data.data,
        });
    };
};

/**
 * 用户修改密码
 * @returns
 */
export const updatePwd = (value: any) => {
    return async () => {
        const res = await axios.post<ApiRequest<user>>('/api/UpdatePassword', value);
        if (res.data.code === '200') {
            message.success(res.data.msg);
        }
    };
};
